package com.spring.boot.mapper;

import com.spring.boot.pojo.Emp;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface IEmpMapper {
    //通过注解删除
    @Delete("delete from emp where id=#{id}")
    public int delete(Integer id);

    /**
     * Options返回主键
     */
    @Options(useGeneratedKeys = true, keyProperty = "id")
    //通过注解新增
    @Insert("insert into emp (username, name, gender, image, job, entry_date, dept_id, create_time, update_time) " +
            "values (#{username},#{name},#{gender},#{image},#{job},#{entryDate},#{deptId},#{createTime},#{updateTime} )")
    public int insert(Emp emp);

    //通过注解更新
    @Update("update emp set username =#{username},name=#{name},gender=#{gender},image=#{image},job=#{job},update_time=#{updateTime} where id=#{id}")
    public int update(Emp emp);

    @Results({
         @Result(column = "entry_date",property = "entryDate")
    })
    //通过注解查询 #开启mybatis的驼峰命名自动映射开关 mybatis.configuration.map-underscore-to-camel-case=true 开启开关后不需要其他注解（@Result）
    @Select("select * from emp where id=#{id}")
    public Emp getById(Integer id);

    //通过注解条件查询
    @Select("select * from emp where name like concat('%',#{name},'%') and gender=#{gender} and entry_date between #{begin} and #{end} order by update_time desc")
    public List<Emp> getListByCondition(String name, Short gender, LocalDate begin,LocalDate end);

    //通过xml mapper配置
    public List<Emp> getListByXml(String name, Short gender, LocalDate begin,LocalDate end);

    public int updateDynamicSql(Emp emp);

}
